In [ ]:
import numpy as np
import pandas as pd
In [ ]:
""" Essa linha permite plotar em um notebook """
%matplotlib inline
In [ ]:
import matplotlib.pyplot as plt
In [ ]:
""" Configurando o Matplotlib para o modo manual """
plt.interactive(False)
In [ ]:
""" definindo as variáveis """
x = np.linspace(-2 * np.pi, 2 * np.pi, 100)
y = np.sin(x)
In [ ]:
""" construindo a figura """
plt.plot(x, y)
In [ ]:
""" mostrando a figura """
plt.show()
In [ ]:
""" criando na mão o objeto Figure de 12 por 8 polegadas """
plt.figure(figsize=(12, 8))
In [ ]:
""" Construindo a figura """
plt.plot(x, y)
plt.show()
In [ ]:
""" construindo o plot """
plt.figure(figsize=(12, 8))
plt.plot(x, y)
In [ ]:
""" adicionando textos explicativos """
plt.xlabel("eixo X")
plt.ylabel("eixo Y")
plt.title("senóide")
In [ ]:
"""a última coisa a ser feita, pois esvazia o buffer de imagem """
plt.show()
In [ ]:
""" construindo o plot """
plt.figure(figsize=(12, 8))
plt.xlabel("eixo X")
plt.ylabel("eixo Y")
plt.title("senóide")
plt.plot(x, y)
In [ ]:
""" redimensionando a janela de visualização"""
plt.xlim(-2 * np.pi, 0.01)
plt.ylim(-2, +2)
In [ ]:
""" visualizando """
plt.show()
In [ ]:
""" construindo o plot """
plt.figure(figsize=(12, 8))
plt.xlabel("eixo X")
plt.ylabel("eixo Y")
plt.title("senóide")
plt.xlim(-np.pi, np.pi)
plt.ylim(-1.2, +1.2)
plt.plot(x, y)
In [ ]:
""" adicionando grid """
plt.grid(True)
In [ ]:
""" visualizando """
plt.show()
In [ ]:
""" construindo o plot """
plt.figure(figsize=(12, 8))
plt.xlabel("eixo X")
plt.ylabel("eixo Y")
plt.title("senóide")
plt.xlim(-np.pi, np.pi)
plt.ylim(-1.2, +1.2)
plt.grid(True)
In [ ]:
""" customização """
plt.plot(
x, y,
color="r",
linewidth=3,
linestyle=":"
)
In [ ]:
""" visualizando """
plt.show()
In [ ]:
""" definindo as variáveis """
x = np.linspace(-2 * np.pi, 2 * np.pi, 100)
y1 = np.sin(x)
y2 = np.cos(x)
y3 = x * 0.333334
In [ ]:
""" construindo o plot """
plt.figure(figsize=(12, 8))
plt.xlabel("eixo X")
plt.ylabel("eixo Y")
plt.title("senóide")
plt.xlim(-np.pi, np.pi)
plt.ylim(-1.2, +1.2)
plt.grid(True)
In [ ]:
""" construindo o plot """
plt.plot(
x, y1, "r-",
x, y2, "g--",
x, y3, "b:"
)
In [ ]:
""" inserindo a legenda; descomente outras linhas para variar a posição da legenda """
local = "best"
# local = "upper right"
# local = "upper left"
# local = "lower left"
# local = "lower right"
# local = "right"
# local = "center left"
# local = "center right"
# local = "lower center"
# local = "upper center"
# local = "center"
plt.legend(["seno", "cosseno", "reta"], loc=local)
In [ ]:
plt.show()
In [ ]:
""" construindo o plot """
plt.figure(figsize=(12, 8))
plt.xlabel("eixo X")
plt.ylabel("eixo Y")
plt.title("senóide")
plt.xlim(-np.pi, np.pi)
plt.ylim(-1.2, +1.2)
plt.grid(True)
In [ ]:
""" construindo o plot """
plt.plot(x, y1, color="red", linewidth=2, linestyle="-")
plt.plot(x, y2, color="green", linewidth=4, linestyle="--")
plt.plot(x, y3, color="blue", linewidth=6, linestyle=":")
In [ ]:
""" inserindo a legenda; descomente outras linhas para variar a posição da legenda """
# por padrão, loc = "best"
plt.legend(["seno", "cosseno", "reta"])
In [ ]:
plt.show()
In [ ]:
""" definindo as variáveis """
x = np.linspace(-2 * np.pi, 2 * np.pi, 100)
y1 = np.sin(x)
y2 = np.cos(x)
y3 = x * 0.333334
y4 = np.tan(x)
y5 = np.cosh(x)
In [ ]:
""" construindo o plot """
plt.figure(figsize=(12, 8))
plt.xlabel("eixo X")
plt.ylabel("eixo Y")
plt.title("senóide")
plt.xlim(-np.pi, np.pi)
plt.ylim(-2, +5)
plt.grid(True)
plt.plot(x, y1, color="red", linewidth=1, linestyle="-")
plt.plot(x, y2, color="green", linewidth=2, linestyle="--")
plt.plot(x, y3, color="blue", linewidth=3, linestyle=":")
plt.plot(x, y4, color="darkorange", linewidth=4, linestyle="--")
plt.plot(x, y5, color="k", linewidth=5, linestyle="-")
plt.legend(["seno", "cosseno", "reta", "tangente", "cosseno hiperbólico"])
In [ ]:
""" salvando PDF """
plt.savefig("senoide.pdf")
In [ ]:
""" salvando PNG """
plt.savefig("senoide.png")
In [ ]:
""" mostrando apenas após salvar """
plt.show()
In [ ]:
import seaborn as sns
In [ ]:
""" definindo as variáveis """
x = np.linspace(-2 * np.pi, 2 * np.pi, 100)
y1 = np.sin(x)
y2 = np.cos(x)
y3 = x * 0.333334
In [ ]:
""" encapsulando o plot """
def plot_curves():
plt.figure(figsize=(12, 8))
plt.plot(x, y1, color="red")
plt.plot(x, y2, color="green")
plt.plot(x, y3, color="blue")
plt.legend(["seno", "cosseno", "reta"])
plt.show()
In [ ]:
""" plot sem SNS """
plot_curves()
In [ ]:
""" plot com SNS """
sns.set()
plot_curves()
Construir o plot da curva ROC usando as ferramentas dadas em cada item.
Referência para a curva ROC: https://en.wikipedia.org/wiki/Receiver_operating_characteristic
O resultado esperado pode ser visto na figura abaixo.
<img src="images/modulo_1-desafio.png")>
In [ ]:
x = np.array([ 0. , 0. , 0.01960784, 0.01960784, 0.07843137,
0.07843137, 0.09803922, 0.09803922, 0.11764706, 0.11764706,
0.1372549 , 0.1372549 , 0.15686275, 0.15686275, 0.17647059,
0.17647059, 0.31372549, 0.31372549, 0.33333333, 0.33333333,
0.35294118, 0.35294118, 0.41176471, 0.41176471, 0.45098039,
0.45098039, 0.47058824, 0.47058824, 0.50980392, 0.50980392,
0.56862745, 0.56862745, 1. ])
In [ ]:
y = np.array([ 0.04166667, 0.125 , 0.125 , 0.25 , 0.25 ,
0.29166667, 0.29166667, 0.33333333, 0.33333333, 0.41666667,
0.41666667, 0.5 , 0.5 , 0.54166667, 0.54166667,
0.58333333, 0.58333333, 0.66666667, 0.66666667, 0.75 ,
0.75 , 0.79166667, 0.79166667, 0.83333333, 0.83333333,
0.875 , 0.875 , 0.91666667, 0.91666667, 0.95833333,
0.95833333, 1. , 1. ])
In [ ]:
roc_auc = 0.78594771241830075
In [ ]:
""" Escreva a a Solução Aqui """